
#include "Retrieve_Html.hpp"
#include "Remove_Tag.hpp"
#include "Index.hpp"
#include "Searcher.hpp"
#include "./include/cpp-httplib/httplib.h"

const std::string html_root = "./web_root";

int main()
{
    Searcher searcher;
    searcher.BulidIndex("./raw_url.html");

    httplib::Server svr;
    svr.set_mount_point("/", "./web_root");

    svr.Get("/search" , [&](const httplib::Request &req , httplib::Response &res)
    {
        res.set_header("Access-Control-Allow-Origin", "*");
        if(!req.has_param("query"))
        {
            res.set_content("请指定关键字" , "text/plain");
            return ;
        }

        std::string query = req.get_param_value("query");
        std::string ret = searcher.find(query);
        if(ret == "null")  res.set_content("没有找到" , "text/plain");
        res.set_content(ret , "application/json");
    });

    daemon(true , false);
    svr.listen("0.0.0.0" , 80);
    
    return 0;
}